#version 330

layout(location = 0) out vec4 FragChannel0;
layout(location = 1) out vec4 FragChannel1;
layout(location = 2) out vec4 FragChannel2;
layout(location = 3) out vec4 FragChannel3Transparency;
layout(location = 4) out vec4 FragChannel4TransparencyNormal;
layout(location = 5) out vec4 FragChannel5TransparencyPosition;

in vec3 posInScene;
in vec3 normalInScene;
in vec2 TexCoord1;

uniform float ProjectionNear;
uniform float ProjectionFar;
uniform sampler2D texture001;

uniform vec4 MaterialDiffuseColor;

vec3 formatInOne(vec3 _posInScene)
{
	//-100~100
	float scale = (ProjectionFar - ProjectionNear) * 2;
	float scaleHalf = ProjectionFar - ProjectionNear;

	vec3 noSub = _posInScene + vec3(scaleHalf);
	return noSub / scale;
}

void main()
{
	if(MaterialDiffuseColor.w<1)
	{
		FragChannel0 = vec4(.0000001);
		FragChannel3Transparency = MaterialDiffuseColor;

		FragChannel4TransparencyNormal = vec4(normalInScene, 1);
		FragChannel5TransparencyPosition = vec4(formatInOne(posInScene), 1);
	}
	else
	{
		FragChannel0 = vec4(formatInOne(posInScene),1);
		FragChannel1 = vec4(normalInScene,1);

		float texture001Size = textureSize(texture001, 0).x;
		if (1 < texture001Size)
		{
			FragChannel2 = texture(texture001, TexCoord1);
		}
		else
		{
			FragChannel2 = MaterialDiffuseColor;
		}
	}
	

}